package cn.tedu;

import java.sql.*;

public class Demo03 {
    public static void main(String[] args) throws SQLException {
        //1. 获取连接
        try(Connection conn = DBUtils.getConn()) {
            String sql = "select id,name,money from hero";
            //创建执行SQL语句对象
            Statement s = conn.createStatement();
            //执行查询的SQL
            ResultSet rs = s.executeQuery(sql);
            //4.遍历结果 next下一个,让游标下游,返回值表示是否有下一条数据
            while (rs.next()){
                int id = rs.getInt(1);
                String name = rs.getString(2);
                int money = rs.getInt(3);
                System.out.println(id+":"+name+":"+money);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
